Page({
  data: {
    repairList: [],
    queryData: {
      current: 1,
      pageSize: 3
    },
    isFinished: false,//是否结束
    isLoading: false //是否还在加载中
  },
  onLoad() {
    this.getHouseList()
  },
  async getHouseList() {
    // 节流阀打开
    this.setData({ isLoading: true })
    try {
      //获取列表数据（传入页码和每页数量）
      const res = await wx.http.get('/repair', this.data.queryData)
      // console.log(res)
      //获取成功
      //判断数据是否结束
      if (res.total > this.data.repairList.length) {
        //还有数据，页码加1
        this.setData({
          isFinished: false,
          'queryData.current': this.data.queryData.current + 1
        })
      } else {
        //没有数据
        this.setData({
          isFinished: true
        })

      }
      //将数据追加到列表
      this.setData({
        repairList: [...this.data.repairList, ...res.rows]
      })
    } catch (error) {
      console.log(error)
    } finally {
      this.setData({ isLoading: false })
    }

  },
  onReachBottom() {
    // console.log('到底了')
    if (this.data.isFinished) return wx.utils.toast('没有更多数据了')
    if (this.data.isLoading) return wx.utils.toast('正在加载中')
    this.getHouseList()
  },
  goDetail({ mark }) {
    // console.log(mark);
    wx.navigateTo({
      url: '/repair_pkg/pages/detail/index?id=' + mark.id,
    })
  },
  addRepair() {
    wx.navigateTo({
      url: '/repair_pkg/pages/form/index',
    })
  },
})
